<?php

/*

  Action	$3

  Gain a copy of a card costing up to $6 that the player to your right gained on his last turn.

 */

class Smugglers extends Card implements iAction, iKingdom, iSeaside {

    public function __construct() {
        parent::__construct("Smugglers", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }
    
    public function isImplemented() {
        return true;
    }

    public function getDescription() {
        return array(
            "Gain a copy of a card costing up to $6 that the player to your right gained on his last turn.");
    }

    public function play(Game $game, $isRealCard) {
        $name = $game->getPreviousPlayerName();
        $cards = $game->getGainedCards($name);
        $optional_cards = array();
        $p_six = new Price(6);
        foreach ($cards as $card) {
            $p_card = $card->getPrice($game);
            if ($p_card->compare($p_six) <= 0 && $card instanceof iKingdom) {
                $optional_cards[] = $card;
            }
        }

        if (sizeof($optional_cards) > 0) {

            $optional_cards = getUniqueCards($optional_cards);
            if (sizeof($optional_cards) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose card to gain");
                $card_name = $output[0];
            } else {
                $card_name = $optional_cards[0];
            }

            $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
            ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($card), "gains " . ScreenDisplay::$LMSG);
        } else {
            ScreenDisplay::addScreenMessage($game, true, "gain nothing", "gains nothing");
        }


        $game->cardActionFinished();
        return true;
    }

}

?>